﻿# CMakeList.txt: 顶层 CMake 项目文件，在此处执行全局配置
# 并包含子项目。
#
cmake_minimum_required (VERSION 3.8)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread -std=c++11 -Wl,-rpath=./:./lib")
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True)

# 如果支持，请为 MSVC 编译器启用热重载。
if (POLICY CMP0141)
  cmake_policy(SET CMP0141 NEW)
  set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT "$<IF:$<AND:$<C_COMPILER_ID:MSVC>,$<CXX_COMPILER_ID:MSVC>>,$<$<CONFIG:Debug,RelWithDebInfo>:EditAndContinue>,$<$<CONFIG:Debug,RelWithDebInfo>:ProgramDatabase>>")
endif()

project ("ShuDao")


if("${CMAKE_BUILD_TYPE}" STREQUAL "")
  set(CMAKE_BUILD_TYPE "Debug")
endif()

message(STATUS "编译类型: ${CMAKE_BUILD_TYPE}")

if (${CMAKE_BUILD_TYPE} STREQUAL "Debug")
elseif (${CMAKE_BUILD_TYPE} STREQUAL "Release")
    message(STATUS "CMAKE_BUILD_TYPE Release")
    # Release 配置
    set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -Os -Wall -s")
    set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Os -Wall -s")
endif()

string(TOLOWER ${CMAKE_SYSTEM_NAME} SYSTEM_NAME_LOWER)

set(OUTPUT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/release/${SYSTEM_NAME_LOWER}/${CMAKE_BUILD_TYPE})
set(LIBRARY_OUTPUT_PATH ${OUTPUT_DIR})
set(EXECUTABLE_OUTPUT_PATH ${OUTPUT_DIR})

message(STATUS "Current CMake version: ${CMAKE_VERSION}")

if(CMAKE_SYSTEM_NAME MATCHES "Windows") 
    add_definitions(-DWIN32_LEAN_AND_MEAN)
    add_definitions(-DNOMINMAX)
    add_compile_options("/EHsc")

    #add_definitions(-DFMT_DEPRECATED=1)

    add_compile_options("$<$<C_COMPILER_ID:MSVC>:/utf-8>")
    add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/utf-8>")

endif()

include_directories(${CMAKE_SOURCE_DIR}/submodule/http)
include_directories(${CMAKE_SOURCE_DIR}/submodule/pugixml/src)
include_directories(${CMAKE_SOURCE_DIR}/submodule/ZLToolKit/src)
include_directories(${CMAKE_SOURCE_DIR}/submodule/spdlog/include)
include_directories(${CMAKE_SOURCE_DIR}/submodule/json/single_include)
# include_directories(${CMAKE_SOURCE_DIR}/submodule/rabbitmq-c/include)

message("${CMAKE_SOURCE_DIR}/submodule/spdlog/include")

find_package(PkgConfig REQUIRED)

pkg_search_module(librdkafka REQUIRED rdkafka IMPORTED_TARGET)
pkg_search_module(libuuid REQUIRED uuid IMPORTED_TARGET)

set(BUILD_SHARED_LIBS OFF)

# 包含子项目。
add_subdirectory ("RSU_Client")
add_subdirectory ("submodule")
